package com.qiaoyanqing.ximalaya.discovermodule.discover_adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qiaoyanqing.ximalaya.R;
import com.qiaoyanqing.ximalaya.discovermodule.discover_entity.Voice;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 27265 on 2016/12/13.
 */

public class AnchorDetailsAdapter extends BaseAdapter {
    private List<Voice> list;
    private Context context;

    public AnchorDetailsAdapter(List<Voice> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.voice_item, viewGroup, false);
            viewHolder.photo = ((ImageView) view.findViewById(R.id.anchorPhotos));
            viewHolder.title = ((TextView) view.findViewById(R.id.voice_title));
            viewHolder.anchor = ((TextView) view.findViewById(R.id.voice_anchor));
            viewHolder.playtimes = ((TextView) view.findViewById(R.id.voice_playtimes));
            view.setTag(viewHolder);
        } else {

            viewHolder = ((ViewHolder) view.getTag());
        }
        String url = list.get(i).getCoverSmall();
        Log.d("TAG", url);
        if (viewHolder.photo != null) {
            Picasso.with(context).load(url).into(viewHolder.photo);
        }

        viewHolder.title.setText(list.get(i).getTitle());
        viewHolder.anchor.setText(list.get(i).getNickname());
        viewHolder.playtimes.setText(list.get(i).getPlaytimes());
        return view;
    }

    public class ViewHolder {
        private ImageView photo;
        private TextView title;
        private TextView anchor;
        private TextView playtimes;

        public TextView getPlaytimes() {
            return playtimes;
        }

        public void setPlaytimes(TextView playtimes) {
            this.playtimes = playtimes;
        }

        public ImageView getPhoto() {
            return photo;
        }

        public void setPhoto(ImageView photo) {
            this.photo = photo;
        }

        public TextView getTitle() {
            return title;
        }

        public void setTitle(TextView title) {
            this.title = title;
        }

        public TextView getAnchor() {
            return anchor;
        }

        public void setAnchor(TextView anchor) {
            this.anchor = anchor;
        }
    }
}
